package com.supersoul.myself.entity;

import com.supersoul.myself.entity.base.BaseEntity;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.util.List;

@Data
@Entity
@Table(name = "tb_comment")
@SQLDelete(sql = "update tb_comment set is_delete = 1 where id = ?")
public class Comment extends BaseEntity {

    /**
     * 对哪一片博客的评论, 必填
     */
    @Column(name = "blog_id", nullable = false, length = 64)
    @NotEmpty
    @Size(max = 64, message = "blogId不能超过64个字符")
    private String blogId;

    /**
     * 评论内容, 必填项
     */
    @Column(name = "content", nullable = false, length = 200)
    @Size(max = 200, message = "content不能超过200个字符")
    private String content;


    // 二级评论  对一级评论的评论,  对二级评论的评论
    /**
     * 被回复的评论id, 选填
     */
    @Column(name = "reply_id", length = 64, columnDefinition = "varchar(64) comment '对评论的评论, 选填' ")
    @Size(max = 64, message = "replyId不能超过64个字符")
    private String replyId;

    /**
     * 被回复的人的 id, 用户名
     */
    @Column(name = "replied_user_name", columnDefinition = "varchar(20) comment '被回复的用户名, 选填' ")
    @Size(max = 20, message = "repliedUserName不能超过20个字符")
    private String repliedUserName;

    @Column(name = "replied_user_id", columnDefinition = "varchar(64) comment '被回复的用户Id, 选填' ")
    @Size(max = 64, message = "repliedUserId不能超过64个字符")
    private String repliedUserId;

    /**
     * 一级评论id
     */
    @Column(name = "reply_root_id",  columnDefinition = "varchar(64) comment '根评论, 选填' ")
    @Size(max = 64, message = "replyRootId不能超过64个字符")
    private String replyRootId;

    // 发表评论的用户信息 id,名称
    @Column(name = "creator_id", nullable = false, length = 64)
    @Size(max = 64, message = "creatorId不能超过64个字符")
    private String creatorId;

    @Column(name = "creator_name", nullable = false, length = 20)
    @Size(max = 20, message = "creatorName不能超过20个字符")
    public String creatorName;

    // 二级评论列表
    @Transient
    private List<Comment> replyList;

}
